home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
MACSHELL
/
MS1
/
SHELL_SO
/
READEDIT.C
< prev
next >
Wrap
Text File
|
1992-12-02
|
7KB
|
267 lines
/*
* MacShell Source File
*
* Copyright (c) 1989, 1990, 1991, 1992 Suick Bay Technologies. All rights reserved.
*
*
* RESTRICTIONS ON MacShell program and source code.
*
* Ñ╩MacShell¬ is a product of Suick Bay Technologies and is provided for
* restricted use by the owner of the CDROM "Disk to the future II".
*
* Ñ╩No permission is granted for any commercial use without the written
* consent of the Suick Bay Technologies.
*
* Ñ╩No permission is granted for any redistribution of any kind use without
* the written consent of the Suick Bay Technologies.
*
* Ñ╩Permission is granted to use this for any personal noncommercial use.
*
* Ñ╩You may not distribute source or executable code at all, nor may you
* distribute it with or within a commercial product without the written
* consent of the Suick Bay Technologies. Please send modifications to
* the author for inclusion in updates to the program. Thanks.
*
*
* MacShell¬ IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
* SUICK BAY TECHNOLOGIES SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY MACSHELL
* OR ANY PART THEREOF.
*
* In no event will Suick Bay Technologies be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Suick Bay Technologies has been advised of the possibility of such damages.
*
* Suick Bay Technologies can be reached at:
*
* 8768 Cottonwood lane
* Maple Grove, MN 55369
* Voice: (612) 425-7025
* AppleLink: D5233
*
*
* No parts of this software may be reproduced or stored in a
* retrieval system or transmitted in any form, or any means,
* electronic, mechanical, photocopying, recording or otherwise,
* without the prior written permission of Suick Bay Technologies.
*
* Spread the word and not the disk.
*
* SPK 020790 : Added Untitled edit file on no arguments
* SPK 012290 : Initial
*/
#include "System.h"
#include "Struct.h"
#include "EditU.h"
#include "Global.h"
#include "Mac.h"
#include "Proc.h"
#include "Path.h"
#include "Shell.h"
/*******************************************************************/
int16 read;
void RECallBack( WHandle ShellWh, int16 ProcID, char *path, char *last,
pathType what, int16 vRefNum, long dirID )
{
char str[ 256 ], name[ 256 ];
OSErr err;
int16 i;
long fLen, mem;
CInfoPBRec pb;
WHandle readWh = NULL;
PeditWindRec **MyPedit;
ShellWindRec **MyShell = (ShellWindRec **) (**ShellWh).thing;
strcpy( str, last );
CtoPstr( str );
if( what == pathIsFile )
{
pb.hFileInfo.ioCompletion = NULL;
pb.hFileInfo.ioNamePtr = (StringPtr) str;
pb.hFileInfo.ioVRefNum = vRefNum;
pb.hFileInfo.ioDirID = dirID;
pb.hFileInfo.ioFDirIndex = 0;
err = PBHGetFInfo( &pb, FALSE );
if( err )
return;
if( pb.hFileInfo.ioFlFndrInfo.fdType == 'TEXT' )
{
fLen = pb.hFileInfo.ioFlLgLen + pb.hFileInfo.ioFlRLgLen;
fLen += sizeof( WHandler ) + sizeof( PeditWindRec );
/* check freemem for enough memory */
mem = FreeMem();
if( fLen < (mem - 4096L) )
{
readWh = TextEditInit( TextEditWindowID, str );
MyPedit = (PeditWindRec **) ((**readWh).thing);
HLock( MyPedit );
sprintf( name, "%s:%s", path, last );
strcpy( (char *) (**MyPedit).fileName, last );
CtoPstr( (char *) (**MyPedit).fileName );
MacToPath( name );
procPrintf( ShellWh, ProcID, " %s\n", name );
(**MyPedit).new = 0;
(**MyPedit).vRefNum = vRefNum;
(**MyPedit).dirID = dirID;
ReadFile( vRefNum, dirID, str, (**MyPedit).hPE );
(**MyPedit).readOnly = read;
HUnlock( MyPedit );
#ifdef USERESINFO
ReadResInfo( readWh );
#endif
AdjustVScroll( readWh, FALSE );
}
else
procPrintf( ShellWh, ProcID,
"insufficient memory to load file %s\n", last );
}
}
}
/*******************************************************************/
extern int16 matches; /* number matches to the current path */
LoadFileIntoWind( WHandle ShellWh, int16 ProcID, char *argument )
{
ShellWindRec **MyShell;
WHandle editWh = NULL;
OSErr err;
MyShell = (ShellWindRec **) (**ShellWh).thing;
ExpandPath( ShellWh, ProcID, argument, (ProcPtr) RECallBack,
(**MyShell).pwdVRefNum, (**MyShell).pwdDirID );
if( matches == 0 && read == FALSE ) /* edit a new file */
{
err = CreateFile( argument, 'TEXT' );
ExpandPath( ShellWh, ProcID, argument, (ProcPtr) RECallBack,
(**MyShell).pwdVRefNum, (**MyShell).pwdDirID );
}
ResetShellPWD( ShellWh );
}
/*******************************************************************/
Boolean DoREAD( int16 ProcToken, WHandle ShellWh, int16 ProcID,
char *string )
{
int16 i;
char *cp, argument[ 256 ];
ShellWindRec **MyShell = (ShellWindRec **) (**ShellWh).thing;
switch( ProcToken )
{
case PROC_INIT :
(**MyShell).Proc[ ProcID ].flags = TRUE;
break;
case PROC_TERM :
case PROC_BREAK :
/* Tell the shell that we're done */
SendOutToken( ShellWh, ProcID, PROC_BREAK );
/* Turn ourself off */
(**MyShell).Proc[ ProcID ].ProcActive = FALSE;
break;
case PROC_STDIN :
if( (**MyShell).Proc[ ProcID ].flags )
{
(**MyShell).Proc[ ProcID ].flags = FALSE;
read = TRUE;
for( i = 1; i < (**MyShell).Proc[ ProcID ].argc; i++ )
{
GetArgv( ShellWh, ProcID, i, argument );
if( *argument != '-' )
LoadFileIntoWind( ShellWh, ProcID, argument );
}
/* Tell the shell that we're done */
SendOutToken( ShellWh, ProcID, PROC_BREAK );
/* Turn ourself off */
(**MyShell).Proc[ ProcID ].ProcActive = FALSE;
return( FALSE );
}
}
}
/*******************************************************************/
Boolean DoEDIT( int16 ProcToken, WHandle ShellWh, int16 ProcID,
char *string )
{
int16 i, argc;
char *cp, argument[ 256 ];
ShellWindRec **MyShell;
MyShell = (ShellWindRec **) (**ShellWh).thing;
switch( ProcToken )
{
case PROC_INIT :
(**MyShell).Proc[ ProcID ].flags = TRUE;
break;
case PROC_TERM :
case PROC_BREAK :
/* Tell the shell that we're done */
SendOutToken( ShellWh, ProcID, PROC_BREAK );
/* Turn ourself off */
(**MyShell).Proc[ ProcID ].ProcActive = FALSE;
break;
case PROC_STDIN :
if( (**MyShell).Proc[ ProcID ].flags )
{
(**MyShell).Proc[ ProcID ].flags = FALSE;
read = FALSE;
argc = (**MyShell).Proc[ ProcID ].argc;
if( argc == 1 )
TextEditInit( TextEditWindowID, "\pUntitled" );
else
for( i = 1; i < argc; i++ )
{
GetArgv( ShellWh, ProcID, i, argument );
if( *argument != '-' )
LoadFileIntoWind( ShellWh, ProcID, argument );
}
/* Tell the shell that we're done */
SendOutToken( ShellWh, ProcID, PROC_BREAK );
/* Turn ourself off */
(**MyShell).Proc[ ProcID ].ProcActive = FALSE;
return( FALSE );
}
}
}